#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: update_standard_clamp_20210511.py
# @time: 2021/5/11 11:01
# @desc:
from .utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from .views.configs import STANDARD_CLAMP_COLLECTION

standard_clamps = retrieve_all_mongo_values({}, collection_name=STANDARD_CLAMP_COLLECTION)

for i in standard_clamps:
    if "safe_constant" not in i["data"].keys():
        i["data"]["safe_constant"] = 0
    if "safe_z" not in i["data"].keys():
        i["data"]["safe_z"] = 0
    if "version" not in i["data"].keys():
        i["data"]["version"] = 2

    update_mongo_value(
        filter_condition={"number": i["number"]},
        new_value={"$set": i},
        collection_name=STANDARD_CLAMP_COLLECTION,
    )